/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Chatree Siangklom
 * Created On : Dec 18, 2012  12:07:42 PM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : apps
 * File Name : TransactionHistorys.java
 * TODO
 */
package apps;

import jpa.entitys.promis.construction.CostTxnStatusHistory;
import jpa.entitys.promis.construction.VwSyncContract;
import jpa.service.promis.construction.CostTxnStatusHistoryServices;

import org.apache.log4j.Logger;

/**
 * 
 * @author Chatree Siangklom of Administrator
 * Date =Nov 13, 2013 : 2:26:29 PM 
 * CreateBy=Chatree Siangklom
 * 
 * TransactionHistorysService
 * TODO
 */
public class TransactionHistorysService {
	
	private static final Logger log = Logger.getLogger(TransactionHistorysService.class);
	
	/**
	 * 
	 * Date =Nov 13, 2013 : 2:26:23 PM 
	 * CreateBy=Chatree Siangklom
	 * CostTxnStatusHistory
	 * TODO
	 * @param company
	 * @param project
	 * @param documentNo
	 * @return
	 * @throws Exception
	 */
	public CostTxnStatusHistory GetConsLowRiseContractTxnHistory(String company, String project, String documentNo) throws Exception {
		try{
			String modelCode = company + "-" + project + "-" + documentNo;
			long revision = 0;
			return new CostTxnStatusHistoryServices(sessionFactory.CreateEmPromis()).findByLastedTxnHistoryWithRevision(modelCode, revision);
		}catch(Exception e){
			e.printStackTrace();
			throw e;
		}
	}
	
	/**
	 * 
	 * Date =Nov 13, 2013 : 2:26:26 PM 
	 * CreateBy=Chatree Siangklom
	 * CostTxnStatusHistory
	 * TODO
	 * @param vwSyncContract
	 * @return
	 * @throws Exception
	 */
	public CostTxnStatusHistory GetConsLowRiseContractTxnHistory(VwSyncContract vwSyncContract) throws Exception {
		try{
			if(vwSyncContract != null){
				String modelCode = vwSyncContract.getCompany() + "-" + vwSyncContract.getProject() + "-" + vwSyncContract.getDocumentNo();
				long revision = 0;
				return new CostTxnStatusHistoryServices(sessionFactory.CreateEmPromis()).findByLastedTxnHistoryWithRevision(modelCode, revision);
			}
		}catch(Exception e){
			log.error(e.getMessage());
			throw e;
		}
		return null;
	}
}
